//
//  ViewController.swift
//  SwiftDemo
//
//  Created by hs on 2017/7/10.
//  Copyright © 2017年 jiachen. All rights reserved.
//

import UIKit

class ViewController: UIViewController,UITextFieldDelegate {
    let lab2 = UILabel.init()
    var lab1:UILabel!
    var a:CGFloat = 0
    
    override func viewDidLoad() {
        super.viewDidLoad()
        let label = UILabel(frame:CGRect.init(x: 10, y: 50, width: 200, height: 20)) //UILabel.init(frame:CGRect(x:10,y:50,width:200,height:200));
        label.text = "xxxxx"
        label.textColor = UIColor.red
        self.view .addSubview(label);
        
        lab2.frame = CGRect(x:10,y:80,width:200,height:20)
        lab2.text = "yyyyy"
        lab2.textColor = UIColor(red: 255, green: 0, blue:255, alpha:0.5)
        self.view.addSubview(lab2)
        let btn1 = UIButton.init(type: UIButtonType.custom)
        btn1.frame = CGRect.init(x:0, y:0, width:100, height:50)
   //     btn1.backgroundColor = UIColor.blue
        btn1.layer.borderColor = UIColor.red.cgColor;
        btn1.layer.borderWidth = 1;
        btn1.center = self.view.center
        btn1.addTarget(self, action:#selector(self.btnAction), for: UIControlEvents.touchUpInside)
        
        self.view .addSubview(btn1)
        let p1 = Student("Tom",("math","A"),"1.jpg")
        print(p1.name,p1.coordinates.0,p1.coordinates.1)
        
        let button:UIButton = UIButton(type:.contactAdd)
        button.frame=CGRect(x:10,y:150,width:100,height:50)
        button.setTitle("按钮", for:UIControlState.normal )
        button.backgroundColor = UIColor.red
        button.addTarget(self,action:#selector(ViewController.buttonClick),for:.touchUpInside)
        self.view .addSubview(button)
        
        let textFiled:UITextField = UITextField.init(frame: CGRect.init(x:80, y:50, width:200, height:60))
        self.view.addSubview(textFiled)
        textFiled.borderStyle = UITextBorderStyle.bezel
        textFiled.isSecureTextEntry = false
        textFiled.placeholder = "输入中文"
        textFiled.delegate = self
        
        self.addStudent(name:"CHEN", 15)
        // Do any additional setup after loading the view, typically from a nib.
    }
    
    @objc private func btnAction(){
        
        print("xxxxx")
        lab2.text = "swift"
        a = 123
        print(a)
    }
    
   @objc func buttonClick(){
        print("yyyyyyy");
        let hvc = HomeViewController.init()
        self.present(hvc, animated: true) {
         hvc.view.backgroundColor = UIColor.white
        }
        
        
    }
    //MARK:_
    func textFieldDidEndEditing(_ textField: UITextField) {
        
    }
    //TODO:明天继续
    func textFieldDidBeginEditing(_ textField: UITextField) {
        print("xxxxx")
    }
    //FIXME:此处有bug
    func textFieldShouldReturn(_ textField: UITextField) -> Bool {
        textField.resignFirstResponder()
        return true
    }
    
    fileprivate func addStudent(name:String,_ age:Int) {
        print(name,age)
    }
    
    func decrease() {
        print("zzzzzzzz")
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
    }
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
    }
    
    override func viewDidDisappear(_ animated: Bool) {
        super.viewDidDisappear(animated)
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

